<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="人大要闻"></uni-navbar></view>

		<u-tabs class="btm-tabs" bg-color="#e5231a" inactive-color="#f5f7fa" active-color="#fff" :list="tabsList" :current="tabsCurrent" @change="tabsChange" :is-scroll="true"></u-tabs>

		<view class="list-box">
			<view class="list-info_05" v-for="(item, index) of newlist" :key="index" @tap="navTo(item)">
				<view class="info-title">{{ item.TITLE }}</view>
				<view class="info-btm">
					<view class="btm-left" style="display: block; width: 100%; clear: both">
						<text class="left-name">{{ item.LAIYUAN }}</text>
						<text class="left-name">丨</text>
						<text class="left-name">{{ item.CHNLNAME }}</text>

						<text class="left-time" style="float: right">{{ item.PUBLISH_TIME }}</text>
					</view>
				</view>
			</view>
			<view class="load-more"><u-loadmore :status="loading" /></view>
		</view>

		<u-back-top :scroll-top="scrollTop" top="200"></u-back-top>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			scrollTop: 0,
			tabsCurrent: 0,
			tabsList: [
				{
					name: '最新动态',
					value: 1
				},
				{
					name: '视察调研',
					value: 2
				},
				{
					name: '机关党建',
					value: 3
				},
				{
					name: '县市人大',
					value: 4
				},
				{
					name: '民主党派',
					value: 5
				},
				{
					name: '文史资料',
					value: 6
				}
			],
			colorMap: {
				0: '#0099ff',
				1: '#ff9900',
				2: '#19be6b'
			},
			newlist: [],

			chnlids: '3449992',
			loading: 'loadmore'
		};
	},
	onLoad() {
		this.loadLogin();
		this.loadData();
	},
	onPullDownRefresh() {
		this.loadData('refresh');
	},
	onReachBottom() {
		if (this.loading == 'loadmore') this.loadData('add');
	},
	onPageScroll(res) {
		this.scrollTop = res.scrollTop;
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.sysUser) {
				this.clientCode = this.userInfo.sysUser.clientCode;
			} else {
				// this.clientCode = '370705';
				this.$logout();
			}
			this.pageNum = 1;
			this.pageSize = 10;
		},
		loadData(type = 'add') {
			if (this.loading == 'loading') {
				return false;
			}
			if (type == 'add') {
				if (this.loading == 'nomore') {
					return false;
				}
				this.loading = 'loading';
			} else {
				this.loading = 'loading';
			}
			if (type != 'add') {
				this.pageNum = 1;
			}
			let data = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				chnlids: this.chnlids
			};
			this.$request('/webNews', data, {
				load: true
			}).then((res) => {
				let count = 0;
				if (type != 'add') {
					uni.stopPullDownRefresh();
					this.newlist = [];
				}
				this.loading = this.pageNum < Math.ceil(res.data.allnum / this.pageSize) ? 'loadmore' : 'nomore';
				this.pageNum = this.pageNum + 1;
				this.newlist = this.newlist.concat(res.data.infolist);
				this.loaded = true;
				if (this.newlist.length <= 0) {
					this.loading = 'nodata';
				}
			});
		},
		tabsChange(index) {
			this.tabsCurrent = index;
			this.type(this.tabsList[index].value);
		},
		// search(e) {
		// 	this.title = e;
		// 	this.chnlids.title = e;
		// 	this.loadData('refresh');
		// },
		type(e) {
			if (e == '1') {
				e = '3449992';
			}
			if (e == '2') {
				e = '3449726';
			}
			if (e == '3') {
				e = '25098759';
			}
			if (e == '4') {
				e = '4770740';
			}
			if (e == '5') {
				e = '3449440';
			}
			if (e == '6') {
				e = '3449176';
			}

			this.chnlids = e.toString();
			this.loadData('refresh');
		},
		navTo(item) {
			uni.navigateTo({
				url: '/pages/news/detail?PUBURL=' + item.PUBURL + '&CHNLDN=' + item.CHNLDN
			});
		}
	}
};
</script>

<style lang="scss">
.u-back-top {
	bottom: 105upx !important;
}
.list-box {
	padding: 0 30upx;
	background-color: #f5f7fa;
}
.clamp {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	display: block;
}
</style>
